package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.OrderDTO;
import com.itheima.pojo.OrderVO;
import com.itheima.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 体检预约
     * @param orderDTO
     * @return
     */
    @PostMapping("/submitOrder")
    public Result addOrder(@RequestBody OrderDTO orderDTO){
        log.info("体检预约：{}", orderDTO);
        Integer id = orderService.addOrder(orderDTO);
        return new Result(true, MessageConstant.ORDER_SUCCESS, id);
    }

    @PostMapping("/findById")
    public Result findById(Integer id){
        log.info("根据id查询预约信息：{}", id);
        OrderVO orderVO = orderService.findById(id);
        return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS, orderVO);
    }
}
